package org.linlinjava.litemall.wx.controller;

import cn.hutool.core.util.StrUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.wx.annotation.LogAnno;
import org.linlinjava.litemall.wx.annotation.LoginUser;
import org.linlinjava.litemall.wx.dto.CardDTO;
import org.linlinjava.litemall.wx.service.IdCardService;
import org.linlinjava.litemall.core.payment.clover.vo.CardInfoReqVO;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import java.io.IOException;
@Api(tags = "信用卡API")
@RestController
@RequestMapping("/wx/idCard")
@RequiredArgsConstructor
public class IdCardController {

    //获取code -> 获取 access_token ->   保存用户 ｜ 请求交易
    //获取API Token 请求所有API

    private final IdCardService idCardService;

    @ApiOperation("clover获得code--沙盒环境使用")
    @GetMapping("acquireCode")
    @LogAnno
    public Object acquireCode(@RequestParam("merchant_id") String merchantId,
                              @RequestParam("employee_id") String employeeId,
                              @RequestParam("client_id") String clientId,
                              @RequestParam("code") String code){
        return idCardService.acquireCode(merchantId,employeeId,clientId,code);
    }



    @ApiOperation("绑定信用卡-「卡号｜令牌」")
    @PostMapping("createCard")
    @LogAnno
    public Object createCard(@LoginUser Integer userId,@RequestBody CardInfoReqVO cardInfo){
        return idCardService.createCloverCard(userId,cardInfo);
    }

    @ApiOperation("卡列表-「卡列表｜clover官方」")
    @GetMapping("cardList")
    @LogAnno
    public Object cardList(@LoginUser Integer userId){
        return ResponseUtil.okList(idCardService.cardInfoByUserIdList(userId));
        //return ResponseUtil.okList(idCardService.cardList(userId));
    }

    @ApiOperation("移除信用卡-「用户｜卡号」")
    @DeleteMapping("deleteCard")
    @LogAnno
    public Object deleteCard(@LoginUser Integer userId,@RequestParam("cardId") String cardId){
        return idCardService.deleteCard(userId,cardId);
    }









    @ApiOperation("绑定信用卡-「数据库」")
    @PostMapping("create")
    @LogAnno
    public Object create(@ApiIgnore @LoginUser Integer userId, @RequestBody CardDTO dto) throws Exception{
        return idCardService.createCard(userId,dto.getIdCardDto(),dto.getAddress());
    }

    @ApiOperation("信用卡详情-「用户｜卡号」")
    @GetMapping("detail")
    @LogAnno
    public Object detail(@ApiIgnore@LoginUser Integer userId, Integer cardId) throws Exception{
        return idCardService.detail(userId,cardId);
    }

    @ApiOperation("个人信用卡列表-「登陆用户｜数据库」")
    @GetMapping("list")
    @LogAnno
    public Object list(@ApiIgnore@LoginUser Integer userId){
        return idCardService.list(userId);
    }

    @ApiOperation("移除信用卡-「卡号」")
    @DeleteMapping("delete")
    @LogAnno
    public Object delete(@RequestParam Integer cardId){
        return idCardService.delete(cardId);
    }



}
